<template>
  <div class="content">
    <div v-if="carList.length > '0'">
      <div class="FirstCar" @click="carDetails(carListFirst)">
        <div class="imageBox" :style="{
          'background': 'url(' + 'http://cheyipai.ucarcloud.cn/auctionCarFile/' + carListFirst.car_main_pic + ') no-repeat center center',
          'backgroundSize': '100% auto'
        }"></div>
        <div class="texBox">
          <h3>
            【{{carListFirst.storage}}】 {{carListFirst.car_style}}
          </h3>
          <p>
            {{carListFirst.mileage}}万公里 | {{carListFirst.register_date}}上牌
          </p>
          <span>
            {{carListFirst.plate_number}}
          </span>
        </div>
        <div class="phone">
          <div class="phone_box">
            <img src="../../../../../static/img/home/home_nav_tel.png" alt="">
            <span>400-877-9737</span>
          </div>
        </div>
      </div>
      <ul>
        <li v-for="(item, i) in carList" class='liCar' @click="carDetails(item)" v-if="i > 0" :key="item.id">
          <div class="imageBox" :style="{
            'background': 'url(' + 'http://cheyipai.ucarcloud.cn/auctionCarFile/' + item.car_main_pic + ') no-repeat center center',
            'backgroundSize': '100% auto'
          }">
          </div>
          <div class="texBox">
            <h3>
              【{{item.storage}}】 {{item.car_style}}
            </h3>
            <p>
              {{item.mileage}}万公里 | {{item.register_date}}上牌
            </p>
            <span>
              {{item.plate_number}}
            </span>
          </div>
          <div class="phone">
            <div class="phone_box">
              <img src="../../../../../static/img/home/home_nav_tel.png" alt="">
              <span>400-877-9737</span>
            </div>
          </div>
        </li>
      </ul>
      <pagination class="pagination1" :page-size="pageSize" :item-count="totalCount" @gotopage="gotopage"></pagination>
    </div>
    <div v-else class="isNodata">
      <div>
        <img src="../../../../../static/img/PersonalCenter/img_car_nodata.png" />
        <p>暂无车辆</p>
      </div>
    </div>
  </div>
</template>
<script>
// 引入分页
import pagination from '../../../../components/pagination.vue'
export default {
  data () {
    return {
      carList: {},
      carListFirst: {},
      userLis: {},
      pageSize: '1',
      totalCount: '6',
      getpages: {
        userId: '',
        index: '1',
        pageSize: '6'
      }
    }
  },
  components: {pagination},
  mounted () {
    // 读取本地
    let storage = window.sessionStorage
    let json = storage.getItem('WSKuserLis')
    let jsonObj = JSON.parse(json)
    if (jsonObj) {
      this.userLis = jsonObj.data.data.user
    }
    this.getpages.userId = this.userLis.id
    this.getMyBuyCar()
  },
  watch: {
    getpages: {
      handler: function (val, oldVal) {
        this.getMyBuyCar()
      },
      deep: true
    }
  },
  methods: {
    // 获取数据
    getMyBuyCar () {
      // $('html, body').animate({
      //   'scrollTop': 0
      // }, 500)
      let _this = this
      this.$http({
        url: 'http://paimai.ucarcloud.cn/auctionCarCore/user/myPurchaseCar',
        params: _this.getpages,
        headers: {'from': 'web'}
      }).then(r => {
        // console.log(r)
        // r.data.data.content.splice(1)
        // let con = r.data.data.content
        _this.carList = r.data.data.content
        for (let i = 0; i < _this.carList.length; i++) {
          _this.carList[i].register_date = _this.carList[i].register_date.substring(0, 4) + '年' + _this.carList[i].register_date.substring(5, 7) + '月'
          _this.carList[i].mileage = (_this.carList[i].mileage / 10000).toFixed(2)
        }
        _this.carListFirst = _this.carList[0]
        _this.pageSize = r.data.data.size
        _this.totalCount = r.data.data.totalElements
        // console.log(_this.carList)
      })
    },
    // 点击分页
    gotopage (val) {
      this.getpages.index = val
    },
    // 点击进入详情
    carDetails (x) {
      if (x.status === '0' || x.status === '2' || x.status === '5' || x.status === '7') {
        this.$router.push({path: '/buyCar/DetailsPage', name: '/buyCar/DetailsPage', query: x})
      } else {
        this.$router.push({path: '/personal/carDetails', name: '/personal/carDetails', query: x})
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.content{
  .liCar{
    overflow: hidden;
    padding: 10px 30px;
    border-top: 1px solid #e3e3e3;
    cursor: pointer;
    .imageBox{
      width: 180px;
      height: 120px;
      float: left;
      background-size: 100% auto !important;
    }
     .texBox{
      float: left;
      margin-left: 20px;
      color: #333;
      width: 510px;
      h3{
        font-size: 16px;
        margin-top: 10px;
        overflow: hidden;
        height: 16px;
        white-space:nowrap;
        text-overflow:ellipsis;
        margin-left: -9px;
      }
      p{
        font-size: 14px;
        color: #666;
        margin: 28px 0;
      }
      span{
        font-size: 14px;
        color: #333;
      }
    }
    .phone{
      float: right;
      font-size: 14px;
      color: #ff6f3c;
      width: 150px;
      height: 32px;
      line-height: 32px;
      border-radius: 4px;
      border: 1px solid #ff6f3c;
      margin-top: 44px;
      .phone_box{
        width: 80%;
        height: 20px;
        margin: 7px auto;
        overflow: hidden;
        img{
          width: 16px;
          height: 20px;
          float: left;
        }
        span{
          float: left;
          height: 20px;
          line-height: 20px;
          margin-left: 8px;
        }
      }
    }
  }
  .FirstCar{
    overflow: hidden;
    padding: 30px 30px 10px;
    cursor: pointer;
    .imageBox{
      width: 180px;
      height: 120px;
      float: left;
      background-size: 100% auto !important;
    }
    .texBox{
      float: left;
      margin-left: 20px;
      color: #333;
      width: 510px;
      h3{
        font-size: 16px;
        margin-top: 10px;
        overflow: hidden;
        height: 16px;
        white-space:nowrap;
        text-overflow:ellipsis;
        margin-left: -9px;
      }
      p{
        font-size: 14px;
        color: #666;
        margin: 28px 0;
      }
      span{
        font-size: 14px;
        color: #333;
      }
    }
    .phone{
      float: right;
      font-size: 14px;
      color: #ff6f3c;
      width: 150px;
      height: 32px;
      line-height: 32px;
      border-radius: 4px;
      border: 1px solid #ff6f3c;
      margin-top: 44px;
      .phone_box{
        width: 80%;
        height: 20px;
        margin: 7px auto;
        overflow: hidden;
        img{
          width: 16px;
          height: 20px;
          float: left;
        }
        span{
          float: left;
          height: 20px;
          line-height: 20px;
          margin-left: 8px;
        }
      }
    }
  }
  .pagination1{
    margin-top: 20px;
    margin-bottom: 35px;
  }
  .isNodata{
    div{
      width: 200px;
      height: 180px;
      margin: 320px auto;
      img{
        width: 200px;
        height: 142px;
      }
      p{
        text-align: center;
        margin-top: 20px;
        font-size: 18px;
        color: #666;
        width: 185px;
      }
    }
  }
}
</style>
